//===============================================================================
// Microsoft patterns & practices
// Web Client Software Factory
//===============================================================================
// Copyright � Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;

using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.ObjectBuilder;

namespace MVPComposibility.ContactManager.Views
{
	public class PopupEditorPresenter : Presenter<IPopupEditorView>
	{
		private ContactManagerController _controller;

		public PopupEditorPresenter([CreateNew] ContactManagerController controller)
		{
			_controller = controller;
		}

		public override void OnViewInitialized()
		{
			base.OnViewInitialized();
			View.HideContactDetailsPopup();
		}

		public override void OnViewLoaded()
		{
			base.OnViewLoaded();
			WireUpEvents();
		}

		private void WireUpEvents()
		{
			View.ContactListView.SelectedContactIndexChanged += ContactListView_SelectedContactIndexChanged;
			View.ContactDetailsView.SaveChanges += ContactDetailsView_SaveChanges;
			View.ContactDetailsView.DiscardChanges += ContactDetailsView_DiscardChanges;
		}

		void ContactDetailsView_DiscardChanges(object sender, EventArgs e)
		{
			View.HideContactDetailsPopup();
		}

		void ContactDetailsView_SaveChanges(object sender, EventArgs e)
		{
			View.HideContactDetailsPopup();
		}

		void ContactListView_SelectedContactIndexChanged(object sender, EventArgs e)
		{
			View.ShowContactDetailsPopup();
		}
	}
}
